﻿@{
    ViewBag.Title = "Detail";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}@using LeSoft.Application.Code;
<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    var _pstructid = "", _instanceid = "";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });

    function GetTree() {
        var item = {
            height: $(window).height() - 27.5,
            url: "../../PropertyManage/CS_EnergyMeterReading/GetTreeList?OrganizeId=" + _organizeid,
            onnodeclick: function (item) {
                if (item.type == "8") {
                    _instanceid = item.id;
                    _pstructid = "";
                }
                else {
                    _pstructid = item.id;
                    _instanceid = "";
                }
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }

    function GetGrid() {
        var queryJson = {
            condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
            keyword: $("#txt_Keyword").val(),
            Date: $("#txt_Date").val(),
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val()
        }
        queryJson["OrganizeId"] = _organizeid;
        queryJson["PStructId"] = _pstructid;
        queryJson["EnergyMeterInstanceId"] = _instanceid;
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_EnergyMeterReading/GetPageDetailList",
            postData: { queryJson: JSON.stringify(queryJson) },
            type: "post",
            datatype: "json",
            height: $(window).height() - 144.5,
            autowidth: true,
            mtype: "POST",
            colModel: [
                { label: "主键", name: "id", hidden: true },
                { label: "表编号", name: "code", index: "code", width: 100, align: "center", sortable: false },
                { label: "表名称", name: "name", index: "name", width: 100, align: "center", sortable: false },
                { label: "所属房产", name: "allname", index: "allname", width: 200, align: "center", sortable: false },
                { label: "位置描述", name: "psmemo", width: 150, align: "left", sortable: false },
                { label: "抄表期间", name: "batchdate", index: "batchdate", width: 70, align: "center" },
                { label: "权责期间", name: "rightdate", index: "rightdate", width: 70, align: "center" },
                { label: "批次号", name: "batchno", index: "batchno", width: 100, align: "center" },
                {
                    label: "上次抄表时间", name: "lastscaledate", index: "lastscaledate", width: 120, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss') : "无";
                    }
                },
                { label: "上次抄表期间", name: "lastbatchdate", index: "lastbatchdate", width: 100, align: "left" },
                { label: "上次抄表读数", name: "lastscalenum", index: "lastscalenum", width: 100, align: "left" },
                {
                    label: "本次抄表时间", name: "scaledate", index: "scaledate", width: 120, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss') : "无";
                    }
                },
                { label: "本次抄表期间", name: "batchdate", index: "batchdate", width: 100, align: "left" },
                { label: "本次抄表读数", name: "scalenum", index: "scalenum", width: 100, align: "left" },
                { label: "用量", name: "volume", index: "volume", width: 100, align: "left" },
                { label: "调整用量", name: "adjustvolume", index: "adjustvolume", width: 100, align: "left" },
                { label: "单价", name: "unitprice", index: "unitprice", width: 100, align: "left" },
                { label: "金额", name: "price", index: "price", width: 200, align: "left" },
                { label: "抄表人", name: "createusername", index: "createusername", width: 200, align: "left" },
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#gridPager",
            sortname: 'CreateDate desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询点击事件
        $("#btn_Search").click(function () {
            if (!$(".ui-filter-text").next('.ui-filter-list').is(":hidden")) {
                $(".ui-filter-text").trigger("click");
            }
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
            SearchEvent();
        });
    }
    //查询表格函数
    function SearchEvent() {
        var queryJson = {
            condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
            keyword: $("#txt_Keyword").val(),
            Date: $("#txt_Date").val(),
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val()
        }
        queryJson["OrganizeId"] = _organizeid;
        queryJson["PStructId"] = _pstructid;
        queryJson["EnergyMeterInstanceId"] = _instanceid;
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../PropertyManage/CS_EnergyMeterReading/GetPageDetailList",
            postData: { queryJson: JSON.stringify(queryJson) },
            page: 1
        }).trigger('reloadGrid');
    }


    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 135.5);
            }, 200);
            e.stopPropagation();
        });

        //绑定组织机构
        $("#Organize").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "==请选择机构==",
            click: function (item) {
                _organizeid = item.id;
            }
        });
        $("#Organize").ComboBoxTreeSetValue(_organizeid);

        //时间
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            description: null,
            click: function (item) {
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                $("#btn_Search").trigger('click')
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="height:28px;padding-left:0px;"><div id="Organize" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td>
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" type="text" value="@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>

                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                            <td class="formTitle">
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="BatchDate">抄表期间</a></li>
                                        <li><a data-value="RightDate">权责期间</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Date" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyyMM")" onfocus="WdatePicker({ dateFmt: 'yyyyMM' })" />
                            </td>
                            <td class="formValue">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入单号或批次号">
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>

</div>

